﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using CrystalDecisions.CrystalReports.Engine;
using LPV_POS.Baocao;
using CrystalDecisions.Shared;

namespace LPV_POS.mh_baocao
{
    public partial class mh_bc_hanghoatralai : DevExpress.XtraEditors.XtraForm
    {
        xulyngaythangnam ngaythang;
        Mod_baocao baocao;
        thuvien tv;
        DataTable tb;
        string[] s;
        object[] o;


        public mh_bc_hanghoatralai()
        {
            InitializeComponent();
        }

        public mh_bc_hanghoatralai(DataSet dset, ReportDocument rpt)
        {
            InitializeComponent();
            rpt_hanghoatralai(dset,rpt);
        }

        private void mh_bc_hanghoatralai_Load(object sender, EventArgs e)
        {
           
        }
        //---------------------------------------------- Begin in hoa don hang hoa tra lai ----------------------------------------------------------
        private void rpt_hanghoatralai( DataSet dset ,ReportDocument rpt)
        {
           
            try
            {
                 //baocao = new Mod_baocao();
                 //baocao.report_common(rpt);

                 Mod_header_report header_report = new Mod_header_report();
                 header_report.f_header_report(rpt);

                CrystalDecisions.CrystalReports.Engine.TextObject str_thoigian;
                str_thoigian = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tu_denngay"];
                if (Variable.str_tungay != "")
                { 
                    str_thoigian.Text = Variable.str_tungay;
                }
                else
                {
                    str_thoigian.Text = "";
                }

                  CrystalDecisions.CrystalReports.Engine.TextObject str_tenhh;
                 str_tenhh = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_hanghoa"];
                   str_tenhh.Text = Variable.str_tenhanghoa; 
               
                 rpt.SetDataSource(dset.Tables[0]);
                rpt.DataDefinition.FormulaFields["TENKHOHANG"].Text = "{dt_report.TENKHOHANG}" + "";
              //  rpt.DataDefinition.FormulaFields["NGAYTRALAI"].Text = "{dt_report.NGAYTRALAI}" + "";
                //rpt.DataDefinition.FormulaFields["TENBAN"].Text = "{dt_report.TENBAN}" + "";
                rpt.DataDefinition.FormulaFields["TENHH"].Text = "{dt_report.TENHH}" + "";
                rpt.DataDefinition.FormulaFields["DVT"].Text = "{dt_report.DVT}" + "";
                rpt.DataDefinition.FormulaFields["SOLUONG"].Text = "{dt_report.SOLUONG}" +"";

                // chon dia chi luu file excel
                mh_save frm_save = new mh_save();
                frm_save.ShowDialog();
                if (frm_save.path_excel == "")
                    return;
                // xuat file excel
                ExportOptions CrExportOptions = null;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = frm_save.path_excel;
                CrExportOptions = rpt.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                rpt.Export();
                //crystalReportViewer1.ReportSource = rpt;
            }
            catch (Exception)
            {
                rpt.Dispose();
                //throw;
            }
            //crystalReportViewer1.Dispose();
            //rpt.Dispose();
        }
        //---------------------------------------------- End in hoa don hang hoa tra lai ----------------------------------------------------------
    }
}